/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.utils;

import org.osgi.framework.Bundle;

/**
 * @author huangmy
 * @date   2008-4-10
 */
public class BundleStatePrintUtil {
	/**
	 * 打印标题
	 * 
	 * @return
	 */
    public static String title() {
    	return print("ID", "STATE", "BUNDLE");
    }
    
    /**
     * 打印内容
     * 
     * @param id
     * @param state
     * @param bundleName
     * @return
     */
    public static String print(Bundle bundle) {
    	String t = String.format("%3s    %12s    %s", bundle.getBundleId(), getStateName(bundle), bundle.getSymbolicName());
		return t;
	}
    
    /**
     * 打印内容
     * 
     * @param id
     * @param state
     * @param bundleName
     * @return
     */
    public static String print(String id, String state, String bundleName) {
    	String t = String.format("%3s    %12s    %s", id, state, bundleName);
    	return t;
    }
    
    /**
	 * 状态名
	 * 
	 * @param bundle
	 * @return
	 */
    public static String getStateName(Bundle bundle) {
		int state = bundle.getState();
		switch (state) {
			case Bundle.UNINSTALLED :
				return "UNINSTALLED ";
			case Bundle.INSTALLED :
				return "INSTALLED   ";
			case Bundle.RESOLVED :
				return "RESOLVED    "; 
			case Bundle.STARTING :
				return "STARTING    ";
			case Bundle.STOPPING :
				return "STOPPING    ";
			case Bundle.ACTIVE :
				return "ACTIVE      ";
			default :
				return Integer.toHexString(state);
		}
	}
}
